import util from '/lib/js/webutil'

Page({
    data: {
        year:[],
        month:[1,2,3,4,5,6,7,8,9,10,11,12],
        day:[],
        value:[1,1,1,1,1,1,1],
        bhour:[],
        ehour:[],
        bmin:[],
        emin:[],
        prickShow:true,
        otdate:'',
        staffid:'',
        infoss:'',
        jxfs:'',
       
    },
    onLoad() {



    var that=this;











  dd.getStorage({
  key: 'staffid',
  success: function(res) 
  { 

    dd.httpRequest({
          url:'http://ding.tida-lighting.com/api/leave/saltype?staffid='+res.data,
          success: function (re) {
          console.log(re);
          that.setData({
          jxfs:re.data.jxfs,


          });

         },
        fail: (err) => {
           //dd.alert({content: JSON.stringify(err)})
           console.log(err);
        }

     })


    //console.log(res.data);
  that.setData({

   staffid:res.data

   






  });},});

        let value = [1]
        let data = new Date()
            
        // 年
        let year = []
       

        

        year[0] = Number(data.getFullYear()) -1
       
       
        for(var i=0;i<3;i++ ){
           
           year[i]=Number(data.getFullYear()) -1+i;

        }
        for(var i=0;i<24;i++)
        {
          this.data.bhour[i]=i;
          this.data.ehour[i]=i;


        }
         for(var i=0;i<60;i++)
        {
          this.data.bmin[i]=i;
          this.data.emin[i]=i;


        }


        // 月
        let month = Number(data.getMonth())+1
        // 当前月在数组的index
        value[1] = this.data.month.indexOf(month)

        // 这个月有多少天
        let day = []
        let maxDay = Number(util.mGetDate(year[1],month))
        // 动态添加当前月的所有天数
        for(let i=1;i<=maxDay;i++){
            day.push(i)
        }
        // 今天在数组的index
        value[2] = day.indexOf(data.getDate())
        value[3]=0,
        value[4]=0,
        value[5]=0,
        value[6]=0,
        // for(){}
        this.setData({
            year,
            day,
            value
        })

    },
    onChange(e) {
       let that=this;
    	// y用户改变月份后 天数对着改变
        let year = this.data.year[e.detail.value[0]];
        let month = this.data.month[e.detail.value[1]];
        let tday=this.data.month[e.detail.value[2]];
        let shour=this.data.month[e.detail.value[3]];
        let smin=this.data.month[e.detail.value[4]];
  
        let fhour=this.data.month[e.detail.value[5]];
        let fmin=this.data.month[e.detail.value[6]]; 
       
         


        // 这个月有多少天
        let day = []
        let maxDay = Number(util.mGetDate(year,month))
        // 动态添加当前月的所有天数
        for(let i=1;i<=maxDay;i++){
            day.push(i)
        }
         var oos=year+'-'+month+'-'+tday+'-'+shour+'-'+smin+'-'+fhour+'-'+fmin+'-'+oos;
        this.setData({
            value: e.detail.value,
            
        });

      console.log(e.detail.value);
      console.log(e.detail.value[0]);
      console.log(that.data.year[e.detail.value[0]]);
      var  infos='';
      infos+= that.data.year[e.detail.value[0]]+'-';
      infos+=that.data.month[e.detail.value[1]]+'-';
      infos+=that.data.day[e.detail.value[2]]+'-';
      infos+=that.data.bhour[e.detail.value[3]]+'-';
      infos+=that.data.bmin[e.detail.value[4]]+'-';
      infos+=that.data.ehour[e.detail.value[5]]+'-';
      infos+=that.data.emin[e.detail.value[6]];
      
      

      console.log(e.detail.value[0]);

       console.log(infos);
        this.setData({
            otdate: infos,
            
        });
        

    },apply:function()
    {
      let that=this;
    //  console.log ('cont='+this.otdate+'& contentStr='+ this.contentStr);
      dd.navigateTo({
       url:'../OvertimeSign/OvertimeSign?cont='+that.otdate+'& contentStr='+ that.contentStr,
        });
    },
    bindFormSubmit: function(e) {
  //  console.log(e.detail.value.textarea+'---'+this.data.otdate);
   // var ows=e.detail.value.textarea;
    //  this.setData({
    //         infoss: e.detail.value.textarea,
            
    //     });
    var that=this;
       console.log('otdate---------'+that.data.otdate)
       console.log('infoss---------'+e.detail.value.textarea)
    dd.navigateTo({
       url:'../OvertimeSign/OvertimeSign?cont='+that.data.otdate+'&infoss='+e.detail.value.textarea+'&jim=helloword',
        });
  }
        


}
);
